package it.koutifaris.travianmap.importer;

import it.koutifaris.travianmap.mapsqlparser.MapSqlEntry;
import it.koutifaris.travianmap.model.Alliance;
import it.koutifaris.travianmap.model.MapSquare;
import it.koutifaris.travianmap.model.Player;
import it.koutifaris.travianmap.model.Tribe;
import it.koutifaris.travianmap.model.Village;

public class MapSqlEntryExploder {

	private Village village;
	private Alliance alliance;
	private Player player;
	private Tribe tribe;
	private MapSquare mapSquare;

	public MapSqlEntryExploder() {
		init();
	}

	protected void init() {
		village = new Village();
		mapSquare = new MapSquare();
		player = new Player();
	}

	public void explode(MapSqlEntry entry) {
		mapSquare.setId(entry.getId());
		mapSquare.setX(entry.getX());
		mapSquare.setY(entry.getY());
		mapSquare.setVillage(village);

		village.setId(entry.getVillageId());
		village.setName(entry.getPlayerName());
		village.setLocation(mapSquare);
		village.setOwner(player);
		village.setPopulation(entry.getVillagePopulation());

		tribe = Tribe.valueOf(entry.getTribeId());

		player.setId(entry.getPlayerId());
		player.setName(entry.getPlayerName());
		player.setAlliance(alliance);
		player.setTribe(tribe);

		alliance.setId(entry.getAllianceId());
		alliance.setName(entry.getAllianceName());
	}

	public Village getVillage() {
		return village;
	}

	public Alliance getAlliance() {
		return alliance;
	}

	public Player getPlayer() {
		return player;
	}

	public Tribe getTribe() {
		return tribe;
	}

	public MapSquare getMapSquare() {
		return mapSquare;
	}

}
